package pattern.behavior.resChain;

import java.util.Optional;

/**
 * @author : Rookie
 * @description :
 * @date : 2023/8/14
 */
public abstract class AbstractHandler {

    protected AbstractHandler handler;

    public AbstractHandler connect(AbstractHandler handler) {
        this.handler = handler;
        return handler;
    }

    public void handle() {
        // 调用当前的处理方法
        this.doHandle();
        // 如果还有后续节点就往下走
        Optional.ofNullable(handler).ifPresent(AbstractHandler::handle);
    }

    public abstract boolean doHandle();
}
